package net.magicidea;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BookItemView extends LinearLayout{
	private static final SimpleDateFormat bookTimeformatter = new SimpleDateFormat("MM/dd hh:mm");
	
 	private ImageView icon;
	private TextView amountTextView;
	private TextView timeTextTextView;
	
	public BookItemView(Context context) {
		super(context);
	}
	
	
	
	public BookItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
	}

	@Override
	protected void onFinishInflate() {
		
		super.onFinishInflate();
		
		icon = (ImageView) findViewById(R.book_item_view.icon);
		amountTextView = (TextView) findViewById(R.book_item_view.amount);
		timeTextTextView = (TextView) findViewById(R.book_item_view.time);
		
		
		timeTextTextView.setTextColor(Color.BLACK);
	}



	public void setAmount(int amount)
	{
		amountTextView.setText(String.valueOf(amount) + " 元");
	}
	
	public void setTime(Date time)
	{
		timeTextTextView.setText(bookTimeformatter.format(time));
	}
	
	public void setImage(int imageResource)
	{
		this.icon.setImageResource(imageResource);
	}
	
	public static BookItemView create(Context context)
	{
		LayoutInflater inflator = LayoutInflater.from(context);
		BookItemView view = (BookItemView) inflator.inflate(R.layout.book_item, null);
		return view;
	}

	

}
